import Vue from "vue";
import App from "./App";
import store from "./store";
import d2Admin from "@/plugin/d2admin"; // 核心插件
import storage from "@/utils/storage";
import * as filters from "@/filters"; // global filters
import router from "./router"; // 菜单和路由设置
// import "@/utils/directives.js";
import "./components/componentRegister.js";

// 核心插件
Vue.use(d2Admin);
Vue.config.silent = true;
Vue.prototype.$Storage = storage;
Vue.prototype.$searchCellWidth = window.innerWidth >= 1920 ? 4 : 6;
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});
new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    this.$store.dispatch("d2admin/size/set", "mini");
    // 处理路由 得到每一级的路由设置
    // this.$store.commit("d2admin/page/init", frameInRoutes);
    // 设置顶栏菜单
    // this.$store.commit("d2admin/menu/headerSet", menuHeader);
    // 设置侧边栏菜单
    // this.$store.commit("d2admin/menu/asideSet", menuAside);
    // 初始化菜单搜索功能
    // this.$store.commit("d2admin/search/init", menuHeader);
  },
  mounted() {
    // 展示系统信息
    this.$store.commit("d2admin/releases/versionShow");
    // 用户登录后从数据库加载一系列的设置
    this.$store.dispatch("d2admin/account/load");
    // 获取并记录用户 UA
    // this.$store.commit("d2admin/ua/get");
    // 初始化全屏监听
    this.$store.dispatch("d2admin/fullscreen/listen");
  },
  watch: {
    // 监听路由 控制侧边栏显示
    "$route.matched"(val) {
      const fullPath = val[0].path;
      this.$store.dispatch("d2admin/menu/switchAsideMenu", fullPath);
    }
  }
}).$mount("#app");
